/**
 * 
 */
package email.view;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import email.model.Email;

/**
 * Shows all mails in a table.
 * @author Dominik Roth
 *
 */
public class MailTable extends AbstractTableModel {

	private String[] columnNames = {"Date / Time", "Sender", "Receiver", "Subject"};
	private ArrayList<Email> mails = null;
	private Object[][] data = null;
	
	public MailTable(ArrayList<Email> mails)
	{
		this.mails = mails;
		data = new Object[this.mails.size()][5];
		for(int i=0;i<this.mails.size();i++)
		{
			//data[i][0] = new Boolean(false);
			data[i][0] = mails.get(i).getDate();
			data[i][1] = mails.get(i).getSender();
			data[i][2] = mails.get(i).getReceiverAsString();
			data[i][3] = mails.get(i).getSubject();
		}
	}
	
	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return data.length;
	}
	
	public Email getRow(int i)
	{
		return mails.get(i);
	}

	public Object getValueAt(int row, int col) {
		return data[row][col];
	}
	
	public String getColumnName(int col) {
	      return columnNames[col];
	}
	
	public Class getColumnClass(int c) {
	      return getValueAt(0, c).getClass();
	}
	
	public boolean isCellEditable(int row, int col) {
	        return false;
	}
	
	public void setValueAt(Object value, int row, int col) {
	      data[row][col] = value;
	      fireTableCellUpdated(row, col);
	}

}
